<template>
  <!-- 采购订单-->
  <div class="page">
    <!-- 条件筛选 -->
    <div class="page_filter">
      <el-input v-model="form.queryString" clearable placeholder="单号/说明">
        <template slot="prepend">查询条件</template>
      </el-input>
      <el-select v-model="form.storeStatus" style="width: 150px;" clearable placeholder="出库状态">
        <el-option
          v-for="item in EnumOutOrderStatusSelectList"
          :key="item.code"
          :label="item.name"
          :value="item.code">
        </el-option>
      </el-select>
      <el-select v-model="form.volumeStatus" style="width: 150px;" clearable placeholder="付款状态">
        <el-option
          v-for="item in EnumVolumeInStatusList"
          :key="item.code"
          :label="item.name"
          :value="item.code">
        </el-option>
      </el-select>
      <el-select v-model="form.orderStatus" style="width: 150px;" clearable placeholder="审核状态">
        <el-option
          v-for="item in EnumSaleOrderStatusList"
          :key="item.code"
          :label="item.name"
          :value="item.code">
        </el-option>
      </el-select>
      <el-select v-model="form.companyId" clearable filterable placeholder="请选择客户公司">
        <el-option
          v-for="item in companyList"
          :key="item.id"
          :label="item.name"
          :value="item.id">
        </el-option>
      </el-select>
      <el-button class="common_btn-defalut" icon="el-icon-search" @click="form.page=1;queryList()">搜索</el-button>
    </div>
    <div class="page_main">
      <el-button icon="iconfont iconcangpeitubiao_chuangjianrukudan icon_size_15" class="common_btn-small"
                 @click="addOrder()">填写销售单
      </el-button>
      <!-- table -->
      <div class="common_btnBox">
        <i class="iconfont iconzongshu icon-size"></i>
        总数：{{form.total}}
      </div>
      <el-table :data="tableList" border>
        <el-table-column label="序号" fixed width="80">
          <template slot-scope="scope">
            {{getIndex(scope.$index)}}
          </template>
        </el-table-column>
        <el-table-column prop="saleOrderNo" label="单号" width="170"></el-table-column>
        <el-table-column prop="orderType" show-overflow-tooltip label="出库状态" width="110">
          <template slot-scope="scope">
            <el-tag :style="scope.row.storeStatus| gradeInOrderStatusColor" style="color: white" size="mini">
              {{scope.row.storeStatusName}}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="volumeStatus" show-overflow-tooltip label="付款状态" width="110">
          <template slot-scope="scope">
            <el-tag :style="scope.row.volumeStatus| gradeInOrderStatusColor" style="color: white" size="mini">
              {{scope.row.volumeStatusName}}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="orderStatusName" show-overflow-tooltip label="审核状态" width="120">
          <template slot-scope="scope">
            <el-tag :style="scope.row.orderStatus| orderStatusColor" style="color: white" size="mini">
              {{scope.row.orderStatusName}}
            </el-tag>
            <p style="font-size: 10px;color: #a3a3a3;" v-if="scope.row.orderStatus === 3">
              原因：{{scope.row.rejectExplanation}}</p>
          </template>
        </el-table-column>
        <el-table-column prop="salesVolume" label="销售总额" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="salesVolume2" label="已收账款" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="salesVolume3" label="待收账款" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="explanation" label="备注" show-overflow-tooltip min-width="120"></el-table-column>
        <el-table-column prop="companyName" label="客户单位" show-overflow-tooltip min-width="120"></el-table-column>
        <el-table-column prop="fromUserName" label="业务员" show-overflow-tooltip min-width="120"></el-table-column>
        <el-table-column prop="updateTime" label="销售日期" width="120">
          <template slot-scope="scope">{{scope.row.updateTime | formatTimer2}}</template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="220">
          <template slot-scope="scope">
            <button class="btn_edit" @click="handleEdit(scope.row,true,false)">查看详情</button>
            <button class="btn_add" @click="handleEdit(scope.row,false,false)" v-if="scope.row.orderStatus !== 2">编辑
            </button>
            <button class="btn_add" @click="handleEdit(scope.row,true,true)" v-if="scope.row.orderStatus !== 2">订单确认
            </button>
            <button class="btn_print" @click="orderPrint(scope.row,'报价单')" v-if="scope.row.orderStatus == 2">打印报价单</button>

          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="form.page"
                     :page-size="form.pageSize"    :page-sizes="[10, 20, 30, 40,50,60,70,80,90,100]"
                     layout="sizes, prev, pager, next" :total="form.total">
      </el-pagination>
      <!--  订单填写-->
      <el-drawer
        title="采购订单"
        :visible.sync="isShowAddDialog"
        direction="rtl"
        custom-class="demo-drawer"
        ref="drawer"
        size="60%">
        <div class="demo-drawer__content">
          <div class="goods_compose_class">
            <el-form label-position="right" ref="order" label-suffix="：" :rules="rule" :model="order"
                     label-width="90px">
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item prop="companyId" label="购货单位" style="margin-bottom: 10px;">
                    <el-select v-model="order.companyId" :disabled="isLook" style="width: 90%" clearable filterable
                               placeholder="请选择购货单位">
                      <el-option
                        :disabled="isLook"
                        v-for="item in companyList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                      </el-option>
                    </el-select>
                    <i class="el-icon-refresh icon-size" style="cursor: pointer;"
                       @click="removeAllCompanyStorage"></i>
                  </el-form-item>
                  <el-form-item prop="companyId" label="成交客户" style="margin-bottom: 10px;">
                    <el-select v-model="order.customId" :disabled="isLook" style="width: 90%" clearable filterable
                               placeholder="请选择客户" @focus="focusCustomerList">
                      <el-option
                        :disabled="isLook"
                        v-for="item in customerList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="projectName" label="项目名称" style="margin-bottom: 5px;">
                    <el-input :disabled="isLook" size="small" v-model="order.projectName" style="width: 90%"
                              placeholder="请输入产品应用项目名称"></el-input>
                  </el-form-item>
                  <el-form-item prop="explanation" label="备注">
                    <el-input :disabled="isLook" v-model="order.explanation" type="textarea" style="width: 90%"
                              :autosize="{ minRows: 3, maxRows: 4}"
                              placeholder="请输入销售补充说明"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!--相关文件-->
                  <el-form-item label="相关文件" prop="fileList">
                    <template v-if="isLook">
                      <el-alert
                        :closable="false" title="可点击下载" type="info" show-icon>
                      </el-alert>
                      <a v-for="file in order.fileList" :key="file.url" style="background: #1990FE; color: white"
                         :href="constUrl + file.url"
                         :download="file.name">
                        <el-button icon="el-icon-document" style="background:#1990FE;color: white" size="mini">
                          {{file.name}}
                        </el-button>
                      </a>
                    </template>
                    <template v-else>
                      <el-alert
                        :closable="false" title="建议上传销售单对应的合同文件！" type="info" show-icon>
                      </el-alert>
                      <upload-file :limit="3" v-model="order.fileList" ref="uploadClear"></upload-file>
                    </template>
                  </el-form-item>
                  <!--相关图片-->
                  <el-form-item label="相关图片" prop="picList">
                    <template v-if="isLook">
                      <el-alert
                        :closable="false" title="可点击查看大图" type="info" show-icon>
                      </el-alert>
                      <el-image
                        style="width: 100px; height: 100px;cursor: pointer" :key="img" v-for="img in order.picList"
                        :src="constUrl + img" @click="previewImg(constUrl + img)"
                        fit="fill"></el-image>
                    </template>
                    <template v-else>
                      <el-alert
                        :closable="false" title="建议上传销售相关的图片证明！" type="info" show-icon>
                      </el-alert>
                      <upload-img v-model="order.picList" :limit="3" :size-limit="3" ref="uploadPic"></upload-img>
                    </template>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-button icon="el-icon-plus" type="primary" @click="addGoodsCompose" :disabled="isLook ">添加产品
              </el-button>
              <el-table height="30vh" border :data="order.formationListTemp" class="m-t-24">
                <el-table-column label="名称" min-width="220px">
                  <template slot-scope="scope">
                    <el-select size="small" value-key="id" style="width: 85%" :disabled="isLook"
                               v-model="scope.row.formation" filterable
                               placeholder="请选择货品"
                               clearable>
                      <el-option
                        v-for="item in goodsSelectList"
                        :key="item.id"
                        :label="item.name"
                        :value="item"
                        :disabled="disableGoodsSelect.indexOf(item.id) !== -1">
                        <span style="float: left">{{ item.name }}</span>
                        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.specifications }}</span>
                      </el-option>
                    </el-select>
                    <i class="el-icon-refresh icon-size" style="cursor: pointer;" @click="removeAllGoodsStorage"></i>
                  </template>
                </el-table-column>
                <el-table-column label="类型" min-width="90px">
                  <template slot-scope="scope">
                    {{scope.row.formation?scope.row.formation.goodsEnumName:'---'}}
                  </template>
                </el-table-column>
                <el-table-column label="分类" min-width="100px">
                  <template slot-scope="scope">
                    {{scope.row.formation?scope.row.formation.goodsTypeName:'---'}}
                  </template>
                </el-table-column>
                <el-table-column label="规格" show-overflow-tooltip width="90px">
                  <template slot-scope="scope">
                    {{scope.row.formation?scope.row.formation.specifications:'---'}}
                  </template>
                </el-table-column>
                <el-table-column label="建议单价" width="95px">
                  <template slot-scope="scope">
                    <span v-if="scope.row.formation"> {{scope.row.formation.saleVolume}}</span>
                    <span v-else>---</span>
                  </template>
                </el-table-column>
                <el-table-column label="销售数量" min-width="150px">
                  <template slot-scope="scope">
                    <el-input-number size="small" style="width: 95%" v-if="scope.row.formation"
                                     :disabled="isLook"
                                     v-model="scope.row.formation.formationNumber"
                                     @change="inputDiscountVolume"
                                     :min="1"></el-input-number>
                    <span v-else>---</span>
                  </template>
                </el-table-column>
                <el-table-column label="优惠单价" width="95px">
                  <template slot-scope="scope" v-if="scope.row.formation">
                    <span v-if="scope.row.formation.discountVolume"> {{scope.row.formation.discountVolume}}</span>
                    <span v-else> {{scope.row.formation.saleVolume}}</span>
                  </template>
                </el-table-column>
                <el-table-column label="单品总计" width="95px">
                  <template slot-scope="scope" v-if="scope.row.formation">
                    <span v-if="scope.row.formation"> {{scope.row.formation.discountVolume?  (scope.row.formation.discountVolume*scope.row.formation.formationNumber).toFixed(1)
                      :scope.row.formation.saleVolume*scope.row.formation.formationNumber}}</span>
                    <span v-else> ---</span>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="90" v-if="!isLook">
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      class="btn_delete"
                      @click="handleDeleteImg(scope.$index)">删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div style="text-align: right;margin-top: 5px">
                <el-input disabled style="width: 250px;" class="lowest_class" size="small" v-model="lowestVolume">
                  <template slot="prepend">最低总价</template>
                  <template slot="append">元</template>
                </el-input>
                <el-input disabled class="sales_class" size="small" v-model="salesVolume">
                  <template slot="prepend">建议总价</template>
                  <template slot="append">元</template>
                </el-input>
                <el-input class="discount_class" size="small" :disabled="isLook"
                          v-model="order.discountVolume"
                          @input="inputDiscountVolume">
                  <template slot="prepend">优惠金额</template>
                  <template slot="append">元</template>
                </el-input>
                <p style="margin: 5px 0 20px 0px ">
                  <el-input disabled class="total_class" size="small" v-model="totalSalesVolume">
                    <template slot="prepend">销售总价</template>
                    <template slot="append">元</template>
                  </el-input>
                </p>
              </div>
              <template v-if="order.isConfirm || (isLook && order.orderStatus > 1)">
                <el-row>
                  <el-col :span="7">
                    <el-form-item prop="goodsEnum" label="审核状态" label-width="130px">
                      <el-radio-group :disabled="!order.isConfirm" v-model="orderConfirm.orderStatus">
                        <el-radio-button v-for="item in orderStatusList" :key="item.code" :label="item.code">
                          {{item.name}}
                        </el-radio-button>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item prop="toUserName" label="确认人">
                      <el-input :disabled="isLook" v-model="order.toUserName"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item prop="explanation" label="说明" v-if="orderConfirm.orderStatus === 3">
                      <el-input :disabled="!order.isConfirm" v-model="orderConfirm.explanation"
                                placeholder="情况说明"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </template>
            </el-form>
          </div>
        </div>
        <div class="demo-drawer__footer">
          <el-button @click="isShowAddDialog=false" type="info">取 消</el-button>
          <el-button type="primary" class="common_btn-defalut" @click="validateAddForm">确 定</el-button>
        </div>
      </el-drawer>
      <!--打印表单弹窗-->
      <el-drawer
        :title="orderHeaderName"
        :visible.sync="isShowPrintDialog"
        direction="rtl"
        custom-class="demo-drawer"
        ref="drawer"
        size="40%">
        <div class="demo-drawer__content" style="overflow: auto;height: 80%">
          <div class="box" id="printJS-form">
            <print-form ref="printForms"></print-form>
          </div>
        </div>
        <div class="demo-drawer__footer">
          <el-button @click="isShowPrintDialog=false" type="info">取 消</el-button>
          <el-button type="primary" class="common_btn-defalut" @click="printOrder">确 定</el-button>
        </div>
      </el-drawer>
    </div>

    <x-loading v-show="isLoading"></x-loading>
    <picture-viewer ref="imageViewer"></picture-viewer>
  </div>
</template>
<script>
  import {
    getSaleOrderList,
    addSaleOrder,
    updateSaleOrder,
    updateSaleOrderStatus
  } from '@/services/ERP/order'
  import UploadFile from '@/components/upload-file'
  import ItemMixins from "../item.mixins";
  import UploadImg from '@/components/upload-img'
  import XLoading from '@/components/animation/x-loading.vue'
  import PictureViewer from '@/components/picture-viewer'
  import PrintForm from '@/components/print/indexSales'
  import Format from '@/utils/format'
  import Enums from '@/utils/enums'

  // form表单校验规则
  export default {
    components: {XLoading, UploadFile, UploadImg, PictureViewer, PrintForm},
    mixins: [ItemMixins,Enums],
    data() {
      return {
        form: {
          page: 1,
          pageSize: 10,
          total: 0,
        },
        orderHeaderName: '',
        isShowPrintDialog: false,
        rule: {
          name: {required: true, message: '请输入公司名称'},
        },
        order: {
          goodsList: [],
          formationListTemp: [],
          fileList: [],
          picList: [],
          parentOrderId: ''
        },
        discount: 0,
        orderConfirm: {},
        tableList: [],
        orderList: [],
        EnumOutOrderStatusList: [],
        EnumSaleOrderStatusList: [],
        EnumVolumeInStatusList: [],
        isShowAddDialog: false,
        isLoading: false,
        orderStatusList: [
          {name: '通过', code: 2},
          {name: '不通过', code: 3},
        ],
      }
    },
    computed: {
      //实际售价
      totalSalesVolume() {
        let money = 0;
        this.order.formationListTemp.map(x => {
          if (x.formation) {
            //如果有优惠价格
            if (x.formation.discountVolume) {
              money += x.formation.discountVolume * x.formation.formationNumber
            } else {
              money += x.formation.saleVolume * x.formation.formationNumber
            }
          }
        })
        return parseInt(money)
      },
      //只能销售产品
      goodsSelectList() {
        return JSON.parse(JSON.stringify(this.allGoodsSelectList.filter(x => x.goodsEnum === 3)))
      },
      //建议售价
      salesVolume() {
        let money = 0;
        this.order.formationListTemp.map(x => {
          if (x.formation) {
            money += x.formation.saleVolume * x.formation.formationNumber
          }
        })
        return money
      },
      // 最低售价
      lowestVolume() {
        let money = 0;
        this.order.formationListTemp.map(x => {
          if (x.formation) {
            money += x.formation.lowestVolume * x.formation.formationNumber
          }
        })
        return money
      },
      //公司选择列表
      companyList() {
        return this.allCompanyList.filter(x => x.type !== 1)
      },
      //客户选择列表
      customerList() {
        return this.allCustomerList.filter(x => x.companyId === this.order.companyId)
      },
      EnumOutOrderStatusSelectList() {
        return this.EnumOutOrderStatusList.filter(x => x.code !== 4)
      },
      isLook() {
        return this.order.isLook
      },
      //已经选择了的货品不能再选
      disableGoodsSelect() {
        let list = []
        this.order.formationListTemp.map(x => {
          if (x.formation) {
            list.push(x.formation.id)
          }
        })
        return list
      },
    },
    methods: {
      //确认打印
      printOrder() {
        this.$nextTick(() => {
          this.$refs.printForms.CreateOneFormPage()
        })
      },
      //打印单据
      orderPrint(row, orderHeaderName) {
        this.isShowPrintDialog = true
        this.orderHeaderName = orderHeaderName
        this.order = JSON.parse(JSON.stringify(row))
        let formationListTemp = []
        //处理货品组成数据，用于回显
        this.order.goodsList.map(x => {
          this.goodsSelectList.map(y => {
            if (x.goodsId === y.id) {
              let temp = JSON.parse(JSON.stringify(y))
              temp.formationNumber = x.goodsNumber
              temp.costVolume = x.saleVolume
              temp.discountVolume = x.discountVolume
              formationListTemp.push({formation: temp})
            }
          })
        })
        this.order.formationListTemp = formationListTemp
        //返回建议总价 和销售总价totalSalesVolume
        this.order.salesVolume = this.salesVolume
        this.order.totalSalesVolume = this.totalSalesVolume
        this.printHandel(true)
      },
      printHandel() {
        let time = Format(new Date(this.order.toTime), 'yyyy年MM月dd日')
        //表格头处理，有顺序
        let tableHeader = [
          {title: '序号', width: '30'},
          {title: '产品名称', width: '150'},
          {title: '分类', width: '60'},
          {title: '规格', width: '60'},
          {title: '单价', width: '60'},
          {title: '数量', width: '40'},
          {title: '优惠价', width: '80'},
          {title: '小计', width: '80'},
        ]
        // 这里传总价格
        let tableFooter = [
          this.order.salesVolume,
          this.order.discountVolume,
          this.order.totalSalesVolume,
        ]
        let header = [
          {title: '项目名称', value: this.order.projectName, style: 'table_header_arr'},
          {title: '询价单位', value: this.order.companyName, style: 'table_header_50'},
          {title: '报价日期', value: time, style: 'table_header_100'},
        ]
        //判断优惠价格如果大于零 展示总价和优惠金额
        if (this.order.discountVolume <= 0) {
          tableFooter = [
            this.order.totalSalesVolume,
          ]
          tableHeader = [
            {title: '序号', width: '30'},
            {title: '产品名称', width: '150'},
            {title: '分类', width: '80'},
            {title: '规格', width: '80'},
            {title: '单价', width: '50'},
            {title: '数量', width: '100'},
            {title: '小计', width: '80'},
          ]
        }
        let table = this.order.formationListTemp
        let tableData = []
        //表格td内容处理，顺序和表头对应
        table.map(x => {
          let tableArray = []
          tableArray.push(x.formation.name)
          tableArray.push(x.formation.goodsTypeName)
          tableArray.push(x.formation.specifications)
          tableArray.push(x.formation.saleVolume)
          tableArray.push(x.formation.formationNumber)
          if (this.order.discountVolume > 0) {
            tableArray.push(x.formation.discountVolume)
            tableArray.push((x.formation.discountVolume * x.formation.formationNumber).toFixed(1))
          }else {
            tableArray.push((x.formation.saleVolume * x.formation.formationNumber).toFixed(1))
          }
          tableData.push(tableArray)
        })
        this.$nextTick(() => {
          this.$refs.printForms.getData(header, tableHeader, tableData, tableFooter, this.orderHeaderName, this.order)
        })
      },
      focusCustomerList() {
        if (!this.order.companyId) {
          this.$message('请先选择购货单位！');
          return
        }
      },
      inputDiscountVolume() {
        let list = this.order.formationListTemp.map(x => {
          //一种产品总价优惠占比=单价*数量/建议总价
          //优惠单价=单价-(单价*数量/建议总价)*总优惠/数量
          x.formation.discountVolume = (x.formation.saleVolume - x.formation.saleVolume * x.formation.formationNumber / this.salesVolume * this.order.discountVolume / x.formation.formationNumber).toFixed(1)
          return x
        })
        this.order.formationListTemp = list
        this.$forceUpdate()
      },
      // 查看大图
      previewImg(url) {
        let list = [url]
        this.$refs.imageViewer.showViewer(list, 0)
      },
      //删除一个货品
      handleDeleteImg(index) {
        this.order.formationListTemp.splice(index, 1);
        this.inputDiscountVolume()
      },
      //添加一个货品
      addGoodsCompose() {
        this.order.formationListTemp.push({})
      },
      // 表单提交
      validateAddForm() {
        //如果是查看，且不是出库确认直接关闭弹窗
        if (this.isLook && !this.order.isConfirm) {
          this.isShowAddDialog = false
          return
        }
        this.$refs.order.validate((valid) => {
          if (valid) {
            this.submitOrder()
          }
        })
      },
      async submitOrder() {
        let goodsList = []
        //处理货品组成数据
        this.order.formationListTemp
        this.order.formationListTemp.map((x,index)=> {
          weight:index,
          goodsList.push({
            goodsId: x.formation.id,
            weight:index,
            suggestVolume: x.formation.saleVolume,
            saleVolume: x.formation.discountVolume,
            goodsNumber: x.formation.formationNumber,
            discountVolume: x.formation.discountVolume,
          })
        })
        this.order.suggestVolume = this.salesVolume
        this.order.salesVolume = this.totalSalesVolume
        this.order.goodsList = goodsList
        let form = this.order
        let action = this.order.id ? updateSaleOrder : addSaleOrder
        if (this.order.isConfirm) {
          action = updateSaleOrderStatus
          form = this.orderConfirm
        }
        let res = await action(form)
        if (res.code === 200) {
          this.$notify({
            type: 'success',
            title: '提示',
            message: this.order.id ? '更新成功' : '添加成功！'
          })
          this.isShowAddDialog = false
          this.order.formationListTemp = []
          this.queryList()
        }
      },
      // 获取当前的序号
      getIndex(index) {
        let param = (this.form.page - 1) * this.form.pageSize + index + 1
        return param
      },
      // 分页大小改变
      handleSizeChange(val) {
        this.form.pageSize = val
        this.queryList()
      },
      // 当前页码改变
      handleCurrentChange(val) {
        this.form.page = val
        this.queryList()
      },
      async queryList() {
        this.isLoading = true
        let res = await getSaleOrderList(this.form)
        this.tableList = res.data?.records || []
        this.form.page = Number(res.data?.current)
        this.form.total = Number(res.data?.total)
        this.isLoading = false
      },
      addOrder() {
        this.isShowAddDialog = true
        this.discount = 0
        this.order = {
          formationListTemp: [],
          fileList: [],
          picList: [],
          discountVolume: 0,
          userName: this.user.userName
        }
        this.$nextTick(() => {
          this.$refs.order.clearValidate()
        })
      },
      handleEdit(row, isLook, isConfirm) {
        this.isShowAddDialog = true
        this.order = JSON.parse(JSON.stringify(row))
        let formationListTemp = []
        //处理货品组成数据，用于回显
        this.order.goodsList.map(x => {
          this.goodsSelectList.map(y => {
            if (x.goodsId === y.id) {
              let temp = JSON.parse(JSON.stringify(y))
              temp.formationNumber = x.goodsNumber
              temp.costVolume = x.saleVolume
              temp.discountVolume = x.discountVolume
              formationListTemp.push({formation: temp})
            }
          })
        })
        this.order.isConfirm = isConfirm
        this.order.formationListTemp = formationListTemp
        this.order.isLook = isLook
        if (isConfirm) {
          this.order.toUserName = this.user.userName
        }

        //订单确认
        this.orderConfirm = {
          explanation: isLook ? row.rejectExplanation : '',
          id: row.id,
          orderStatus: row.orderStatus > 1 ? row.orderStatus : 2
        }
        this.$nextTick(() => {
          this.$refs.order.clearValidate()
        })
      },
    },
    mounted() {
      this.queryList()
      this.queryDictList(['EnumOutOrderStatus', 'EnumVolumeInStatus', 'EnumSaleOrderStatus'], ['EnumOutOrderStatusList', 'EnumVolumeInStatusList', 'EnumSaleOrderStatusList'])
    },
    activated() {
      this.getAllGoodsSelectList()
      this.getAllCompanyList()
      this.getAllCustomerList()
    }

  }
</script>

<style lang="less" scoped>

  .goods_compose_class {
    padding: 20px;

    /deep/ .el-table th {
      padding: 5px 0;
    }

    /deep/ .el-table td {
      padding: 5px 0;

      .el-input-number {
        width: 120px;
      }

      .el-input-number__decrease, .el-input-number__increase {
        width: 30px;
      }
    }
  }


  .el-divider__text {
    font-size: 20px;
  }

  /deep/ .el-divider--horizontal {
    display: block;
    height: 1px;
    width: 100%;
    margin: 30px 0;
  }

  /deep/ .el-input-group__prepend {
    border-right: 0;
    background: #2196f3;
    color: white;
  }

  .m-t-24 {
    margin-top: 10px;
  }

  .lowest_class {
    /deep/ .el-input-group__prepend {
      padding: 0 10px;
      background: #e91e63;
    }
  }

  .sales_class {
    width: 250px;
    margin-left: 5px;

    /deep/ .el-input-group__prepend {
      padding: 0 10px;
    }
  }

  .discount_class {
    width: 250px;
    margin-left: 5px;

    /deep/ .el-input-group__prepend {
      background: #1cc01d;
      padding: 0 10px;
    }
  }

  .total_class {
    width: 250px;
    margin-left: 5px;

    /deep/ .el-input-group__prepend {
      padding: 0 10px;
    }
  }
</style>
